home *** CD-ROM | disk | FTP | other *** search
- Path: tbj.dec.com!diamond
- From: diamond@tbj.dec.com (Norman Diamond)
- Newsgroups: comp.std.c
- Subject: Re: Bit-field sizes
- Date: 7 Mar 1996 03:50:05 GMT
- Organization: Digital Equipment Corporation Japan , Tokyo
- Message-ID: <4hlmdd$266@usenet.pa.dec.com>
- References: <nzRPxQ9ytZZA084yn@csn.net>
- Reply-To: diamond@tbj.dec.com (Norman Diamond)
- NNTP-Posting-Host: jit533.tbj.dec.com
-
- In article <nzRPxQ9ytZZA084yn@csn.net>, thads@csn.net (Thad Smith) writes:
- >Can the size of a bit-field, measured in bits, exceed the size of an int?
-
- A program that attempts to do it would have undefined behavior, but a kind
- implementation would define it by extension. On the other hand, an unkind
- implementation could make all bit-fields exceed the size of an int.
-
- >The description of bit-fields describes it as an integral type with a
- >(programmer-)specified number of bits, not specifically constrained in size.
-
- Not quite. ANSI Classic section 3.5.2.1, page 61 lines 15 to 17, has a
- Constraint requiring the specified width to fit in the number of bits in
- an ordinary object of compatible type. So if the type is int then this
- constraint has the effect you say. However, line 30 is a Semantic (not
- Constraint) restricting the size. So, a non-strictly-conforming program
- can take advantage of an implementation extension without even getting a
- diagnostic.
-
- >ANSI Classic section 3.2.1.1 says, however, that bit-fields are promoted
- >to either int or unsigned int. This would seem to prohibit promoting a
- >large bit-field to a long. If so, why was this constraint imposed?
-
- Probably the same reason as most other defects in the standard :-)
-
- >Secondly, is the storage unit within which bit-fields are allocated
- >constrained to be a single size or can it vary, depending on the size
- >of the bit fields? I see nothing in the standard prohibiting
- >different size storage units for bit-fields.
-
- Neither do I. On the other hand, alignment is stated to be unspecified.
- Therefore the silence on variable sizing is ambiguous.
- --
- << If this were the company's opinion, I would not be allowed to post it. >>
- "I paid money for this car, I pay taxes for vehicle registration and a driver's
- license, so I can drive in any lane I want, and no innocent victim gets to call
- the cops just 'cause the lane's not goin' the same direction as me" - J Spammer
-